var role;
$(document).ready(function () {
    //点击教师登录
    $("#login_sub").click(function () {
        role = $("#login_sub").val();
        // alert(val);
        $("#submitForm").attr("onsubmit", "return clickEven()");
        $("#submitForm").attr("action", "../../html/firmeHtml/index.html")
            .submit();
    });
    //点击管理员
    $("#login_admin").click(function () {
        role = $("#login_admin").val();
        $("#submitForm").attr("onsubmit", "return clickEven()");
        $("#submitForm").attr("action", "../../html/firmeHtml/index.html")
            .submit();
    });
    // 点击学生登录
    $("#login_stu").click(function () {
        role = $("#login_stu").val();
        $("#submitForm").attr("onsubmit", "return clickEven()");
        $("#submitForm").attr("action", "../../html/firmeHtml/index.html")
            .submit();
    });
});

/* 回车事件 */
function EnterPress(e) { // 传入 event
    var e = e || window.event;
    if (e.keyCode == 13) {
        $("#submitForm").attr("action", "../../html/firmeHtml/index.html")
            .submit();
    }
}

// 点击事件
function clickEven() {
    // alert(role)
    var name = $("#name").val();
    var password = $("#pwd").val();
    if (null != name && null != password && "" != name && "" != password) {
        // if ("123" != name || "123" != password) {
        // alert("账号或密码错误！");
        // return false;
        // }
        var loginUrl = '/user/login';
        var loginType = 'post';
        var loginData = {
            "username": name,
            "password": password,
            "role": role
        }
        var loginDataType = 'json';
        var message = dataAjax(loginUrl, loginType, loginData,
            loginDataType);
        // alert(JSON.stringify(message));
        if (1 == message[0].code) {
            alert(message[0].result);
            // $("#heddin").html('<input type="hidden" value="'+ message[0].data.limits +'" name="limit">');
            // $("#heddin2").html('<input type="hidden" value="'+ message[0].data.user_id +'" name="userId">');
        } else if (0 == message[0].code) {
            alert(message[0].result);
            return false
        }

    } else {
        alert("用戶名/密码不能为空！");
        return false;
    }
}